#include "fs/fs.h"
#include "fs/buf.h"
#include "fs/bitmap.h"
#include "lib/str.h"
#include "lib/print.h"
#include "fs/inode.h"
#include "fs/dir.h"
#include "fs/dinode.h"

// 超级块在内存的副本
super_block_t sb;

// // 输出super_block的信息
// static void sb_print()
// {
//     printf("super block information:\n");
//     printf("magic = %x\n", sb.magic);
//     printf("block size = %d\n", sb.block_size);
//     printf("inode blocks = %d\n", sb.inode_blocks);
//     printf("data blocks = %d\n", sb.data_blocks);
//     printf("total blocks = %d\n", sb.total_blocks);
//     printf("inode bitmap start = %d\n", sb.inode_bitmap_start);
//     printf("inode start = %d\n", sb.inode_start);
//     printf("data bitmap start = %d\n", sb.data_bitmap_start);
//     printf("data start = %d\n", sb.data_start);
// }

// static char str[BLOCK_SIZE],tmp[BLOCK_SIZE],empty[BLOCK_SIZE];

// 文件系统初始化
void fs_init()
{
    buf_t* buf = buf_read(SB_BLOCK_NUM);
    memcpy(&sb, buf->data, sizeof(sb));
    buf_release(buf);

    // 检查超级块的magic值是否正确，确保文件系统没有损坏
    assert(sb.magic == FS_MAGIC, "fs_init: invalid super block magic number");
    assert(sb.block_size == BLOCK_SIZE, "fs_init: invalid super block size");
}
